#include <Arduino.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <DFRobot_DHT11.h>

#define DHT11_PIN 34

const char *ssid = "二刺螈保护区";

const char *password = "516159357";
const String host = "192.168.137.1";
// const String host = "49.232.88.124";
const uint16_t port = 8080;
const String postUrl = "/mangeData/upload";


String payload = "";

// uint8_t *payload = 1;
DFRobot_DHT11 DHT;
HTTPClient postItem;

void getTemperature();

void setup()
{
  Serial.begin(115200);

  pinMode(0, OUTPUT);

  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  postItem.begin(host, port, postUrl);
  delay(1000);
  
}
void loop()
{

  payload = "";
  delay(5000);

  getTemperature();
  postItem.POST(payload);

  delay(5000);
}


void getTemperature() {
  int temp;

  do {
    DHT.read(DHT11_PIN);

    temp = DHT.temperature;
    Serial.println(temp);
    delay(100);
  } while (temp == 255);
  
  payload = "{\"temperature\":\"" + String(temp)+"\"}";
}
